/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.Slider;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;

/**
 *
 * @author Kvest
 */
public class ProgressForm extends Form implements ActionListener
{
    public static final int CANCEL_ID = 1;
    
    private Command cancel;
    private ProgressFormAction listener;
    
    public ProgressForm()
    {
        this(null);
    }
    
    public ProgressForm(ProgressFormAction listener)
    {
        super("load"); 
        this.listener = listener;

        init();
    }
    
    public void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        final TextArea text = new TextArea((new Label("wait_text")).getText(), 1, 30);
        text.setEditable(false);
        addComponent(text);

        final Slider slider = new Slider();
        slider.setFocusable(false);
        slider.setUIID("Progress");
        slider.setScrollAnimationSpeed(20);
        slider.setInfinite(true);
        addComponent(slider);
   
        if (listener != null)
        {
            cancel= new Command("cancel", CANCEL_ID);
            addCommand(cancel);
        }
        
        addCommandListener(this);
    }
    
    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.progressFormAction(evt.getCommand().getId());
        }
    }
    
    public interface ProgressFormAction
    {
        public abstract void progressFormAction(int commandID);
    }
}
